package com.wz.controller;

import com.wz.config.Normal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.Request;
import org.web3j.protocol.core.methods.response.Web3ClientVersion;
import org.web3j.protocol.http.HttpService;

import java.io.IOException;

/**
 * @program: demo
 * @description: 快速开始
 * @author: Wangzheng
 * @create: 2020-12-16 13:51
 **/
@RestController
@RequestMapping("/QuickStart")
public class QuickStart {
	
	@Autowired
	private static Web3j web3j;
	

	/*
	* 测试链接:http://localhost:8080/QuickStart/method01
	* */
	@RequestMapping("/method01")
	public static void method01() {
		//发送本机运行节点
		web3j = Web3j.build(new HttpService(Normal.SERVER));
		try {
			//构建请求对象:
			Request<?, Web3ClientVersion> web3ClientVersionRequest = web3j.web3ClientVersion();
			//发送请求对象,获取相应对象:
			Web3ClientVersion reponse = web3ClientVersionRequest.send();
			//调用相应对象的方法来取值:
			String clientVersion = reponse.getWeb3ClientVersion();
			//控制台打印链接信息:clientVersion EthereumJS TestRPC/v2.13.1/ethereum-js
			System.out.println("clientVersion " + clientVersion);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/*
	* 可以简写成:String clientVersion1 = web3j.web3ClientVersion().send().getWeb3ClientVersion();
	* 
	* */
}